#include "init_control.hpp"

#ifdef DBG_TAG
#undef DBG_TAG
#endif
#ifdef DBG_LVL
#undef DBG_LVL
#endif

#define DBG_TAG "init_ctl"
#define DBG_LVL DBG_LOG

extern "C"
{
#include <rtdbg.h>
}

extern "C"
{
extern void lvgl_test_thread();
}

void init_all_thread_entry(void *pra)
{
    rt_thread_mdelay(2000);
    {
        //类对象指针初始化
        preset_create_obj();


        //组件初始化部分
        if (global_data_device_init_interface() != data_save_status_ok) while (1)
        {
            LOG_E("data record device cant work,pls contact tech support");
            rt_thread_mdelay(1000);
        }
        else
        {
            LOG_I("data record device init done");
        }
        if( ultra_sonic_uart_init() != chip_uart_status_ok) while(1)
        {
            LOG_E("ultra sonic device cant work,pls contact tech support");
            rt_thread_mdelay(1000);
        }
        else
        {
            LOG_I("ultra sonic device init done");
        }


    }

    { //控制启动部分
        non_status_control_thread_start();

        status_control_thread_start();
    }
}



int init_all()
{
    rt_thread_t tid;
    tid = rt_thread_create("init all", init_all_thread_entry, NULL, 40960, 9, 500);
    if (tid)
    {
        LOG_I("init all thread start!");
        rt_thread_startup(tid);
    }
    return 0;
}

INIT_APP_EXPORT(init_all);
